<?php


abstract class BaseCustomer extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $user_id;


	
	protected $receipt_id;


	
	protected $status_id;


	
	protected $name;


	
	protected $surname;


	
	protected $email;


	
	protected $is_company;


	
	protected $company_name;


	
	protected $company_nr;


	
	protected $fiscal_code;


	
	protected $countrycode;


	
	protected $city;


	
	protected $zip;


	
	protected $street;


	
	protected $phone_nr;


	
	protected $updated_at;


	
	protected $created_at;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getReceiptId()
	{

		return $this->receipt_id;
	}

	
	public function getStatusId()
	{

		return $this->status_id;
	}

	
	public function getName()
	{

		return $this->name;
	}

	
	public function getSurname()
	{

		return $this->surname;
	}

	
	public function getEmail()
	{

		return $this->email;
	}

	
	public function getIsCompany()
	{

		return $this->is_company;
	}

	
	public function getCompanyName()
	{

		return $this->company_name;
	}

	
	public function getCompanyNr()
	{

		return $this->company_nr;
	}

	
	public function getFiscalCode()
	{

		return $this->fiscal_code;
	}

	
	public function getCountrycode()
	{

		return $this->countrycode;
	}

	
	public function getCity()
	{

		return $this->city;
	}

	
	public function getZip()
	{

		return $this->zip;
	}

	
	public function getStreet()
	{

		return $this->street;
	}

	
	public function getPhoneNr()
	{

		return $this->phone_nr;
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = CustomerPeer::ID;
		}

	} 
	
	public function setUserId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = CustomerPeer::USER_ID;
		}

	} 
	
	public function setReceiptId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->receipt_id !== $v) {
			$this->receipt_id = $v;
			$this->modifiedColumns[] = CustomerPeer::RECEIPT_ID;
		}

	} 
	
	public function setStatusId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->status_id !== $v) {
			$this->status_id = $v;
			$this->modifiedColumns[] = CustomerPeer::STATUS_ID;
		}

	} 
	
	public function setName($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->name !== $v) {
			$this->name = $v;
			$this->modifiedColumns[] = CustomerPeer::NAME;
		}

	} 
	
	public function setSurname($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->surname !== $v) {
			$this->surname = $v;
			$this->modifiedColumns[] = CustomerPeer::SURNAME;
		}

	} 
	
	public function setEmail($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->email !== $v) {
			$this->email = $v;
			$this->modifiedColumns[] = CustomerPeer::EMAIL;
		}

	} 
	
	public function setIsCompany($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->is_company !== $v) {
			$this->is_company = $v;
			$this->modifiedColumns[] = CustomerPeer::IS_COMPANY;
		}

	} 
	
	public function setCompanyName($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->company_name !== $v) {
			$this->company_name = $v;
			$this->modifiedColumns[] = CustomerPeer::COMPANY_NAME;
		}

	} 
	
	public function setCompanyNr($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->company_nr !== $v) {
			$this->company_nr = $v;
			$this->modifiedColumns[] = CustomerPeer::COMPANY_NR;
		}

	} 
	
	public function setFiscalCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->fiscal_code !== $v) {
			$this->fiscal_code = $v;
			$this->modifiedColumns[] = CustomerPeer::FISCAL_CODE;
		}

	} 
	
	public function setCountrycode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->countrycode !== $v) {
			$this->countrycode = $v;
			$this->modifiedColumns[] = CustomerPeer::COUNTRYCODE;
		}

	} 
	
	public function setCity($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->city !== $v) {
			$this->city = $v;
			$this->modifiedColumns[] = CustomerPeer::CITY;
		}

	} 
	
	public function setZip($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->zip !== $v) {
			$this->zip = $v;
			$this->modifiedColumns[] = CustomerPeer::ZIP;
		}

	} 
	
	public function setStreet($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->street !== $v) {
			$this->street = $v;
			$this->modifiedColumns[] = CustomerPeer::STREET;
		}

	} 
	
	public function setPhoneNr($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->phone_nr !== $v) {
			$this->phone_nr = $v;
			$this->modifiedColumns[] = CustomerPeer::PHONE_NR;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = CustomerPeer::UPDATED_AT;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = CustomerPeer::CREATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->user_id = $rs->getInt($startcol + 1);

			$this->receipt_id = $rs->getInt($startcol + 2);

			$this->status_id = $rs->getInt($startcol + 3);

			$this->name = $rs->getString($startcol + 4);

			$this->surname = $rs->getString($startcol + 5);

			$this->email = $rs->getString($startcol + 6);

			$this->is_company = $rs->getInt($startcol + 7);

			$this->company_name = $rs->getString($startcol + 8);

			$this->company_nr = $rs->getString($startcol + 9);

			$this->fiscal_code = $rs->getString($startcol + 10);

			$this->countrycode = $rs->getString($startcol + 11);

			$this->city = $rs->getString($startcol + 12);

			$this->zip = $rs->getString($startcol + 13);

			$this->street = $rs->getString($startcol + 14);

			$this->phone_nr = $rs->getString($startcol + 15);

			$this->updated_at = $rs->getTimestamp($startcol + 16, null);

			$this->created_at = $rs->getTimestamp($startcol + 17, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 18; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Customer object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CustomerPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			CustomerPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(CustomerPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

    if ($this->isNew() && !$this->isColumnModified(CustomerPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CustomerPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = CustomerPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += CustomerPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = CustomerPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CustomerPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getUserId();
				break;
			case 2:
				return $this->getReceiptId();
				break;
			case 3:
				return $this->getStatusId();
				break;
			case 4:
				return $this->getName();
				break;
			case 5:
				return $this->getSurname();
				break;
			case 6:
				return $this->getEmail();
				break;
			case 7:
				return $this->getIsCompany();
				break;
			case 8:
				return $this->getCompanyName();
				break;
			case 9:
				return $this->getCompanyNr();
				break;
			case 10:
				return $this->getFiscalCode();
				break;
			case 11:
				return $this->getCountrycode();
				break;
			case 12:
				return $this->getCity();
				break;
			case 13:
				return $this->getZip();
				break;
			case 14:
				return $this->getStreet();
				break;
			case 15:
				return $this->getPhoneNr();
				break;
			case 16:
				return $this->getUpdatedAt();
				break;
			case 17:
				return $this->getCreatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CustomerPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getUserId(),
			$keys[2] => $this->getReceiptId(),
			$keys[3] => $this->getStatusId(),
			$keys[4] => $this->getName(),
			$keys[5] => $this->getSurname(),
			$keys[6] => $this->getEmail(),
			$keys[7] => $this->getIsCompany(),
			$keys[8] => $this->getCompanyName(),
			$keys[9] => $this->getCompanyNr(),
			$keys[10] => $this->getFiscalCode(),
			$keys[11] => $this->getCountrycode(),
			$keys[12] => $this->getCity(),
			$keys[13] => $this->getZip(),
			$keys[14] => $this->getStreet(),
			$keys[15] => $this->getPhoneNr(),
			$keys[16] => $this->getUpdatedAt(),
			$keys[17] => $this->getCreatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CustomerPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setUserId($value);
				break;
			case 2:
				$this->setReceiptId($value);
				break;
			case 3:
				$this->setStatusId($value);
				break;
			case 4:
				$this->setName($value);
				break;
			case 5:
				$this->setSurname($value);
				break;
			case 6:
				$this->setEmail($value);
				break;
			case 7:
				$this->setIsCompany($value);
				break;
			case 8:
				$this->setCompanyName($value);
				break;
			case 9:
				$this->setCompanyNr($value);
				break;
			case 10:
				$this->setFiscalCode($value);
				break;
			case 11:
				$this->setCountrycode($value);
				break;
			case 12:
				$this->setCity($value);
				break;
			case 13:
				$this->setZip($value);
				break;
			case 14:
				$this->setStreet($value);
				break;
			case 15:
				$this->setPhoneNr($value);
				break;
			case 16:
				$this->setUpdatedAt($value);
				break;
			case 17:
				$this->setCreatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CustomerPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUserId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setReceiptId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setStatusId($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setName($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setSurname($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setEmail($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setIsCompany($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCompanyName($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setCompanyNr($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setFiscalCode($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setCountrycode($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setCity($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setZip($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setStreet($arr[$keys[14]]);
		if (array_key_exists($keys[15], $arr)) $this->setPhoneNr($arr[$keys[15]]);
		if (array_key_exists($keys[16], $arr)) $this->setUpdatedAt($arr[$keys[16]]);
		if (array_key_exists($keys[17], $arr)) $this->setCreatedAt($arr[$keys[17]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(CustomerPeer::DATABASE_NAME);

		if ($this->isColumnModified(CustomerPeer::ID)) $criteria->add(CustomerPeer::ID, $this->id);
		if ($this->isColumnModified(CustomerPeer::USER_ID)) $criteria->add(CustomerPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(CustomerPeer::RECEIPT_ID)) $criteria->add(CustomerPeer::RECEIPT_ID, $this->receipt_id);
		if ($this->isColumnModified(CustomerPeer::STATUS_ID)) $criteria->add(CustomerPeer::STATUS_ID, $this->status_id);
		if ($this->isColumnModified(CustomerPeer::NAME)) $criteria->add(CustomerPeer::NAME, $this->name);
		if ($this->isColumnModified(CustomerPeer::SURNAME)) $criteria->add(CustomerPeer::SURNAME, $this->surname);
		if ($this->isColumnModified(CustomerPeer::EMAIL)) $criteria->add(CustomerPeer::EMAIL, $this->email);
		if ($this->isColumnModified(CustomerPeer::IS_COMPANY)) $criteria->add(CustomerPeer::IS_COMPANY, $this->is_company);
		if ($this->isColumnModified(CustomerPeer::COMPANY_NAME)) $criteria->add(CustomerPeer::COMPANY_NAME, $this->company_name);
		if ($this->isColumnModified(CustomerPeer::COMPANY_NR)) $criteria->add(CustomerPeer::COMPANY_NR, $this->company_nr);
		if ($this->isColumnModified(CustomerPeer::FISCAL_CODE)) $criteria->add(CustomerPeer::FISCAL_CODE, $this->fiscal_code);
		if ($this->isColumnModified(CustomerPeer::COUNTRYCODE)) $criteria->add(CustomerPeer::COUNTRYCODE, $this->countrycode);
		if ($this->isColumnModified(CustomerPeer::CITY)) $criteria->add(CustomerPeer::CITY, $this->city);
		if ($this->isColumnModified(CustomerPeer::ZIP)) $criteria->add(CustomerPeer::ZIP, $this->zip);
		if ($this->isColumnModified(CustomerPeer::STREET)) $criteria->add(CustomerPeer::STREET, $this->street);
		if ($this->isColumnModified(CustomerPeer::PHONE_NR)) $criteria->add(CustomerPeer::PHONE_NR, $this->phone_nr);
		if ($this->isColumnModified(CustomerPeer::UPDATED_AT)) $criteria->add(CustomerPeer::UPDATED_AT, $this->updated_at);
		if ($this->isColumnModified(CustomerPeer::CREATED_AT)) $criteria->add(CustomerPeer::CREATED_AT, $this->created_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(CustomerPeer::DATABASE_NAME);

		$criteria->add(CustomerPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setUserId($this->user_id);

		$copyObj->setReceiptId($this->receipt_id);

		$copyObj->setStatusId($this->status_id);

		$copyObj->setName($this->name);

		$copyObj->setSurname($this->surname);

		$copyObj->setEmail($this->email);

		$copyObj->setIsCompany($this->is_company);

		$copyObj->setCompanyName($this->company_name);

		$copyObj->setCompanyNr($this->company_nr);

		$copyObj->setFiscalCode($this->fiscal_code);

		$copyObj->setCountrycode($this->countrycode);

		$copyObj->setCity($this->city);

		$copyObj->setZip($this->zip);

		$copyObj->setStreet($this->street);

		$copyObj->setPhoneNr($this->phone_nr);

		$copyObj->setUpdatedAt($this->updated_at);

		$copyObj->setCreatedAt($this->created_at);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new CustomerPeer();
		}
		return self::$peer;
	}

} 